package cn.wolfcode.trip.base.mapper;

import cn.wolfcode.trip.base.domain.Message;
import cn.wolfcode.trip.base.domain.MessageContent;
import cn.wolfcode.trip.base.query.friend.MessageQuery;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface MessageMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Message record);

    Message selectByPrimaryKey(Long id);

    List<Message> selectAll();

    int updateByPrimaryKey(Message record);

    List<Message> selectForList(MessageQuery qo);

    List<Map<String,Object>> selectForCrowdInvite(MessageQuery qo);

    void updateStateById(@Param("messageId") Long messageId, @Param("state") int state);

    void updateStateByUserAndTarget(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("state") int state,@Param("type")Integer type);

    List<Map<String,Object>> selectMessageDialogClue(Long targetId);

    List<Message> selectMessageByUserTargetTypeState(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("type") Integer type, @Param("state") int state);

    List<MessageContent> selectInviteCrowdMessage(@Param("crowdId") Long crowdId, @Param("userId") Long userId);

    /**
     * 批量添加信息,可以用于后端优化
     * @param list
     */
    void insertList(@Param("list") List<Message> list);

    /**
     * 获取群消息中未读的最早时间
     * @param userId
     * @param targetId
     * @return
     */
    Date selectForTimeByCrowdAndTarget(@Param("userId") Long userId, @Param("targetId") Long targetId);

    /**
     * 按时间查询,获取发送给群的信息
     * @param userId
     * @param date
     * @return
     */
    List<Message> selectForCrowdDialog(@Param("userId") Long userId, @Param("date") Date date);

    List<Map<String,Object>> selectMessageCrowdDialogClue(Long id);

    /**
     * 查询系统通知
     * @param authorId
     * @param type
     * @return
     */
    List<Map<String,Object>> selectMessageByUserId(@Param("authorId") Long authorId,@Param("type")int type);

    /**
     * 更新系统通知的状态为已读
     * @param authorId
     * @param state
     */
    void updateSystemState(@Param("authorId") Long authorId, @Param("state") int state,@Param("type") int type);

    /**
     * 查询系统通知的总数
     * @param authorId
     * @param type
     * @param state
     * @return
     */
    int getSystemNum(@Param("authorId") Long authorId, @Param("state") int state, @Param("type") int type);

    /**
     * 查询私信的数量
     * @param authorId
     * @param state
     * @return
     */
    int selectPrivateNum(@Param("authorId") Long authorId, @Param("state") int state);

    Message getAddFriendMessage(@Param("userId") Long userId, @Param("targetId") Long targetId);
}